<style scoped>
    .wraper {
        padding: 0 20px;
    }

    .search {
        padding-bottom: 20px;
    }

    .search span {
        color: #68777c;
        font-weight: bold;
        padding-right: 18px;
    }

    .search button {
        background-color: #00a8f7;
        color: #fff;
        margin-left: 8px;
    }

    .top {
        margin-bottom: 20px;
        border-top: 1px dashed #cccccc;
    }


    .wraper .headline {
        position: relative;
        font-size: 12px;
        color: #303134;
        font-weight: bold;
        margin: 10px 0;
        line-height: 32px;
    }

    .wraper .add-agent {
        position: absolute;
        top: 0px;
        right: 30px;
        background-color: #348bf2;
        color: #fff;
    }

    .iconfont {
        font-size: 14px;
    }

    .red-font {
        color: #ff1f1f;
    }




    .fixed-bottom {
        padding-left: 20px;
        padding-right: 20px;
        height: 80px;
        line-height: normal !important;
        position: fixed;
        left: 210px;
        right: 0;
        bottom: 0;
        z-index: 999;
        text-align: center;
        background-color: rgb(255, 255, 255);
        box-shadow: 0px 0px 9px 0px rgba(0, 0, 0, 0.28);
    }

    .sidehide {
        left: 75px;
    }


    /* 表格样式 start*/

    .pro-card {
        margin-bottom: 10px;
    }

    .pro-card-head {
        background-color: #e6e7eb;
        line-height: 38px;
        border: 1px solid #ddd;
    }

    .pro-card-title {
        font-size: 14px;
        color: #333;
        font-weight: bold;
        padding-left: 20px;
    }

    .pro-card-headr {
        padding-right: 10px;
        text-align: right;
    }

    .pro-card-content {
        clear: both;
    }

    .pro-paramname {
        text-align: center;
        background-color: #e6e7eb;
        font-size: 14px;
        color: #333;
        border-right: 1px solid #ddd;
    }

    .pro-paramvalue {
        padding-left: 10px;
        border-right: 1px solid #ddd;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    .pro-card-contentrow {
        line-height: 40px;
        border-left: 1px solid #ddd;
        border-bottom: 1px solid #ddd;
    }






    /* 表格样式  end */

    /* 分页 start */

    .page {
        margin: 0;
    }

    .ivu-page {
        padding-bottom: 150px;
    }




    table {
        width: 1200px;
        margin: auto;
    }

    table,
    tr,
    td {
        border: 1px solid #ccc;
        border-collapse: collapse;
    }

    tr {
        height: 36px;
    }

    td {
        min-width: 100px;
        min-height: 30px;
    }

    .mod_table {
        margin-right: 22px;
        margin-top: 20px;
        height: 50px;
    }

    /* 分页 end */
</style>
<style>
    .a-link {
        color: #4074e1;
        text-decoration: underline;
        cursor: pointer;
    }
</style>



<template>
    <div class="policy-manage">
        <product-title></product-title>
        <div class="wraper">
            <div class="pro-con-f common-box-body">
                <Row>
                    <h3 class="search-h3 huang">
                        快速搜索
                    </h3>
                    <Form :model="searchForm" class="search-form">
                        <Col :xs="24" :sm="12" :md="12" :lg="8">
                        <Form-item>
                            <Input size="large" type="text" v-model="searchForm.name" placeholder="请输入员工姓名" />
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="4">
                        <Form-item>
                            <Input size="large" type="text" v-model="searchForm.job_code" placeholder="请输入员工工号" />
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="4">
                        <Form-item>
                            <Input size="large" type="text" v-model="searchForm.post_name" placeholder="请输入岗位" />
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="6">
                        <Form-item>
                            <Select v-model="searchForm.sex" transfer placeholder="请选择性别">
                                <Option value="0">全部</Option>
                                <Option value="1">男</Option>
                                <Option value="2">女</Option>
                            </Select>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="8" v-if="$accountType.filter_org">
                        <Form-item>
                            <!-- <Select v-model="searchForm.rank_id" transfer placeholder="请选择分支机构">
                                            <Option  value="0">全部</Option>
                                            <Option v-for="(value,key) in ranklist" :value="key">{{value}}</Option> 
                                        </Select> -->
                            <Select clearable filterable placeholder="请输入分支机构" v-model="searchForm.yun_org_mid" :transfer=true>
                                <Option value="">全部</Option>
                                <Option v-for="item in orglist" :value="item.id" :key="item.id">{{item.shortn}}</Option>
                            </Select>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="12" :md="12" :lg="4">
                        <Form-item>
                            <Select v-model="searchForm.status" transfer placeholder="请选择状态">
                                <Option value="0">全部</Option>
                                <Option value="1">在职</Option>
                                <Option value="2">离职</Option>
                                <Option value="3">其他</Option>
                            </Select>
                        </Form-item>
                        </Col>
                        <!-- <Col :xs="24" :sm="12" :md="12" :lg="4">
                            <Form-item>
                                <Select v-model="searchForm.dept_id" transfer placeholder="请选择部门">
                                    <Option value="0">全部</Option>
                                    <Option v-for="(value,key) in deptlist" :value="key" :key="key">{{value}}</Option>
                                </Select>
                            </Form-item>
                            </Col> -->                        
                        <Col :xs="24" :sm="12" :md="12" :lg="6">
                        <Form-item>
                            <DatePicker :value="searchForm.joinRange" @on-change="contractchange" transfer format="yyyy-MM-dd" type="daterange" placement="bottom-end"
                                placeholder="请选择入司时间段"></DatePicker>
                        </Form-item>
                        </Col>
                        <Col :xs="24" :sm="24" :md="24" :lg="$accountType.filter_org?6:14">
                        <Button size="large" class="fr" type="primary" icon="ios-search" @click="search">搜索</Button>
                        </Col>
                        <div class="clear"></div>
                    </Form>
                    <Col span="24" class="table-action">
                    <Button type="warning" size="large" v-if="$isShow('employee/create_office')" class="fr" icon="plus" @click="createBtn">新增</Button>
                    <!-- <div style="border-right: 1px solid #EDF2F6;padding-right: 15px;margin-right: 15px;" class="fr">
                                    <span class="clear"></span>
                                    <Button type="primary" size="large" class="fr" icon="icon iconfont icon-riqi"  @click="headSet">表头设置</Button>
                                </div> -->
                    <div style="border-right: 1px solid #EDF2F6;padding-right: 15px;margin-right: 15px;" class="fr">
                        <Button v-if="$isShow('employee/batch_export_offical')" type="info" size="large" class="fr" icon="icon iconfont icon-daochu"
                            @click="exportClick">导出员工</Button>
                    </div>
                    <div v-if="$isShow('employee/leading_office')" style="padding-right: 15px;margin-right: 15px;" class="fr">
                        <!-- <Upload action="" :before-upload="handleUpload" name="file_input" accept=".csv" :format="['csv']">
                                <span class="clear"></span>
                                <Button type="warning" size="large" class="fr" icon="icon iconfont icon-daoru" >导入员工CSV</Button>
                            </Upload> -->
                        <Upload action="" :format="['xlsx']" name="file_input" :before-upload="handleUpload">
                            <Button type="info" size="large" class="fr" icon="icon iconfont icon-daoru">导入员工</Button>
                        </Upload>
                    </div>
                    <div style="border-right: 1px solid #EDF2F6;padding-right: 15px;margin-right: 15px;" class="fr">
                        <a href="https://test.kuaibao365.com/batch_export/download_employee_demo?service_type=1">
                            <Button type="info" size="large" class="fr" icon="icon iconfont icon-daochu">内勤模板下载</Button>
                        </a>
                    </div>
                    </Col>
                </Row>
            </div>
            <div class="detail">
                <div class="clearfix">
                    <div class="table-theme highlight_table">
                        <Table :loading="tableloading" ref="currentRowTable" @on-current-change="tableCurrentChange($event)" size="large" stripe
                            highlight-row border :columns="columns1" :data="tablelist" class=""></Table>
                    </div>
                </div>
            </div>
        </div>
        <div :class="slidetoggle?'fixed-bottom':'fixed-bottom sidehide' ">
            <Row class="pro-pagesize">
                <Col :md="24" :lg="16">
                <Button type="error" v-if="$isShow('employee/del_office')" :disabled="tableaction" @click="tableDel" size="large" class="fl mr10 ">删除</Button>
                <Button type="info" v-if="$isShow('employee/get_detail_office')" :disabled="tableaction" @click="tableEdit" size="large"
                    class="fl mr10">编辑</Button>
                <!-- <Button type="success" :disabled="tableaction" size="large" class="fl mr10" @click="modalTrue">设置账号</Button> -->
                </Col>
                <Col :md="24" :lg="8" class="tRight">
                <Page ref="pages" :current="currentpage" :total="listTotal" show-total show-sizer :page-size="pagesize" @on-change="pageChange"
                    @on-page-size-change="pageSizeChange" placement="top" class="page"></Page>
                </Col>
            </Row>
        </div>
        <Modal v-model="showAddModal" ok-text="提交" :mask-closable='closeable' width="600" title="设置账号信息" :loading="loading" class-name="common-box-body showAddModal">
            <Row>
                <Col>
                <Form :model="org" ref="org" :rules="ruleValidate">
                    <Form-item label="手机号码" prop="login_name" required>
                        <Input :readonly='readonly' v-model="org.phone" placeholder="请输入账号登录名"></Input>
                    </Form-item>
                    <Form-item label="登录密码" prop="pwd" required>
                        <Input v-model="org.pwd" type="password" placeholder="请输入登录密码,至少保证8位"></Input>
                    </Form-item>
                    <Form-item label="确认密码" prop="pwd_two" required>
                        <Input v-model="org.pwd_two" type="password" placeholder="请再次输入登录密码,密码必须一致"></Input>
                    </Form-item>
                </Form>
                </Col>
            </Row>
        </Modal>
        <!--  导出员工 -->
        <Modal v-model="exportModal" :mask-closable='closeable' width="600" title="导出员工" @on-ok="exportOk" :loading="loading">
            <Row class="common-box-body">
                <Col span="18" offset="3" class="search-form">
                <Form :model="exportForm">
                    <Form-item label="选择机构">
                        <Select multiple :disabled="!$accountType.filter_org?true:false" filterable placeholder="请输入分支机构" v-model="exportForm.yun_org_mid"
                            :transfer=true>
                            <Option v-for="item in orglist" :value="item.id" :key="item.id">{{item.shortn}}</Option>
                        </Select>
                    </Form-item>
                    <Form-item label="状态">
                        <Select v-model="exportForm.status" transfer placeholder="请选择">
                            <Option value="0">全部</Option>
                            <Option value="1">在职</Option>
                            <Option value="2">离职</Option>
                            <Option value="3">其他</Option>
                        </Select>
                    </Form-item>
                </Form>
                </Col>
            </Row>
        </Modal>
        <!-- 导入exsl -->
        <Modal v-model="importModal" width="1300" :closable="false" :mask-closable="false">
            <p slot="header" style="color:#fff;text-align:center">
                <Icon type="information-circled"></Icon>
                <span>数据导入展示</span>
            </p>
            <div style="text-align:center">
                <p>{{statustxt}}</p>
                <div>
                    <Row>
                        <Col>
                        <div class="">
                            <Table size="large" stripe border :columns="columns2" :data="policy_list" class="">
                            </Table>
                        </div>
                        </Col>
                    </Row>
                    <div :md="24" :lg="8" class="tRight mod_table">
                        <Page ref="pages2" :total="listTotal2" :page-size="pagesize2" @on-change="pageChange2" placement="top" class="page"></Page>
                    </div>
                </div>
            </div>
            <div class="err_msg" style="color:red"><span>{{err_msg}}</span>
                <span style="color:blue;">{{err_msg2}}</span><span>{{err_msg3}}</span>
            </div>
            <div slot="footer"  :md="24" :lg="8">
                <Button style="width:60px;"  type="primary" size="small tRight" @click="quxiao">取消导入</Button>
                <Button style="width:60px;"  offset="20" class="tRight" v-if="modShow" type="success" size="small" long @click="uploadbBtn">确定导入</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import productTitle from '../../components/productTitle'
    import {
        employeeGetListOffice,
        employeeDelOffice,
        batchExportOffical,
        leading_office,
        add_employee,
        leading_office2,
    } from '../../api/employee'
    import {
        getYunRankList
    } from '../../api/rank'
    import {
        getDeptList
    } from '../../api/yun_dept'
    import {
        getListByName
    } from '../../api/yun_org'
    import {
        formatTime
    } from '../../libs/time'
    import debounce from 'lodash.debounce'
    export default {
        data() {
            const validatePass = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请输入密码'));
                } else {
                    if (this.org.pwd_two !== '') {
                        // 对第二个密码框单独验证
                        this.$refs.org.validateField('pwd_two');
                    }
                    callback();
                }
            };
            const validatePassCheck = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请再次输入密码'));
                } else if (value !== this.org.pwd) {
                    callback(new Error('两次输入的密码不匹配!'));
                } else {
                    callback();
                }
            };
            return {
                canbaolist:[],
                modShow:false,
                err_msg:'',
                err_msg2:'',
                err_msg3:'',
                formData: {},
                exportForm: {
                    yun_org_mid: [],
                    service_type: '',
                    status: ''
                },
                importModal: false, //弹出上传窗口
                uplodeTag: 0, //上传文件的文件做递增操作
                problem_list: [],
                status: 'active',
                statustxt: '数据导入中',
                errortag: 0,
                policy_count: 0,
                policy_list: [],
                mod_list: [],
                mod_th: [],

                exportModal: false,
                readonly: true, //org.phone  弹出框
                showAddModal: false, //点击设置,弹出模态框
                closeable: false, //shif按ese按钮退出
                loading: true, //模态框家在状态提交确定
                closeable: false,
                // loading: true,
                remoteloading: false,
                page: 1,
                pagesize: 10,
                listTotal: 0,
                page2: 1,
                pagesize2: 10,
                listTotal2: 0,
                searchForm: {
                    ginseng_status:'',
                    p: 1,
                    pagesize: 10,
                    name: '',
                    job_code: '',
                    sex: '',
                    rank_id: '',
                    dept_id: '',
                    yun_org_mid: '',
                    joinRange: ['', ''],
                    status: '1',
                },

                oname: '',
                deptlist: {},
                ranklist: {},
                orglist: [],
                proloading: false,
                comoptions: [],
                tableloading: true,
                tableaction: true,
                current: 0,
                currentpage: 1,
                currentRow: {},
                columns1: [{
                        title: '编号',
                        type: 'index',
                        width: '100',
                        align: 'center',
                    },
                    {
                        title: '工号',
                        key: 'job_code',
                        align: 'center',
                    },
                    {
                        title: '姓名',
                        key: 'name',
                        align: 'center',
                    },
                    {
                        title: '性别',
                        key: 'sex',
                        align: 'center',
                    },
                    {
                        title: '年龄',
                        key: 'age',
                        align: 'center',
                    },
                    {
                        title: '手机号',
                        key: 'mobile',
                        align: 'center'
                    },
                    {
                        title: '机构',
                        key: 'org_name',
                        align: 'center'
                    },
                    {
                        title: '部门',
                        key: 'dept_name',
                        align: 'center'
                    },
                    {
                        title: '岗位',
                        key: 'post_name',
                        align: 'center'
                    },
                    {
                        title: '状态',
                        key: 'status',
                        align: 'center'
                    }
                ],
                columns2: [{
                        title: '工号',
                        key: 'job_code',
                        align: 'center',
                    },
                    {
                        title: '姓名',
                        key: 'name',
                        align: 'center',
                    },
                    {
                        title: '证件类型',
                        key: 'id_type',
                        align: 'center',
                    },
                    {
                        title: '证件号码',
                        key: 'id_number',
                        align: 'center',
                    },
                    {
                        title: '性别',
                        key: 'sex_name',
                        align: 'center',
                    },
                    {
                        title: '手机号',
                        key: 'mobile',
                        align: 'center',
                    },
                    {
                        title: '岗位',
                        key: 'service_type',
                        align: 'center',
                    },
                    {
                        title: '信息提示',
                        key: 'err',
                        align: 'center',
                        render: (h, params) => {
                            return h('div', {
                                style: {
                                    color: "red",
                                    fontSize:'12px'
                                },
                            }, params.row.err);
                        }
                    },
                ],

                tablelist: [],
                tablelist2: [],
                org: {
                    phone: '', //手机号
                    pwd: '', //密码
                    pwd_two: '',
                },
                ruleValidate: {
                    phone: [{
                        required: true,
                        message: '手机号码不能为空',
                    }],
                    pwd: [{
                        validator: validatePass,
                        trigger: 'blur'
                    }],
                    pwd_two: [{
                        validator: validatePassCheck,
                        trigger: 'blur'
                    }],

                },
            }
        },
        components: {
            productTitle
        },
        computed: {
            slidetoggle() {
                return this.$store.state.sildeshow
            },
            get_pre() {
                return (this.policy_count > 0 ? parseInt((this.uplodeTag / this.policy_count) * 100) : 0)
            },
        },
        mounted() {
            this.getDept();
            this.getRank();
            this.getList();
            this.orglistinit();
        },
        methods: {

            quxiao(){
                this.importModal = false;
                console.log(this.policy_list,"AA",this.listTotal2)
                this.policy_list=[];
                this.formData.p = 1;
                this.formData.uniqid = '';
                this.listTotal2 = 0;
                this.page2 = 1;
                this.$refs['pages2'].currentPage = 1 
                this.modShow = false;

                console.log(this.policy_list,"BBBB",this.listTotal2)
            },
            get_file_list() {
                new Promise((resolve, reject) => {
                    console.log(this.formData, "////")
                    leading_office2(this.formData).then(response => {
                        if (response.data.err == 0) {
                            this.policy_list = response.data.list;
                            this.listTotal2 = response.data.total;
                        } else {
                            this.$Message.error("上传失败！")
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
                });
            },
            // 页码改变
            pageChange2(page) {
                // this.modShow = true;
                var clie = Math.ceil(this.listTotal2 / 10);
                if (page != clie) {
                    this.modShow = false;
                }else{
                    this.modShow = true;
                }
                this.page2 = page;
                this.formData.p = this.page2;
                console.log(this.formData.uniqid, 'xxx', this.formData)
                this.get_file_list()
            },
            // 提交导入信息
            uploadbBtn() {
                this.sendDatawl(this.policy_list)
                this.$refs['pages2'].currentPage = 1;
                this.modShow = false;
                this.getList()
            },
            // 导入员工数据
            //上传之前
            handleUpload(file) {
                // 先判断是不是exsl文件
                // if (!file || file.length == 0) return;
                // var resultq =/\.[^\.]+/.exec(file[0].name);
                // if(resultq[0]===".xls"||resultq[0]===".xlsx")
                // console.log(resultq,"...resultqA")
                this.importModal = true;
                this.filePare = file;
                let param = new FormData();
                param.append('file', file);
                console.log(param, "...")
                new Promise((resolve, reject) => {
                    leading_office(param).then(response => {
                        if (response.data.err == 0) {
                            this.policy_list = response.data.list;
                            this.listTotal2 = response.data.total;
                            if(this.listTotal2<10){
                                this.modShow = true;
                            }
                            this.formData.uniqid = response.data.uniqid;
                            console.log(this.formData.uniqid, 'xxx', this.formData)
                            this.importModal = true;
                        } else {
                            this.$Message.error("上传失败！")
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
                });
                return false;
            },
            sendDatawl(obj) {
                    new Promise((resolve, reject) => {
                        let _params = {
                            uniqid: this.formData.uniqid
                        }
                        add_employee(_params).then(response => {
                            if (response.data.err == 0) {
                                this.$Message.success('导入成功');
                            } else {
                                this.$Message.error(response.data.msg);
                            }
                             this.importModal = false;
                            resolve();
                        }).catch(error => {
                            this.modal_loading = false
                            this.status = 'wrong'
                            this.statustxt = '导入失败'
                            reject(error);
                        });
                    })
            },
            sendData() {
                if (this.uplodeTag != this.policy_count) {
                    console.log(this.uplodeTag, "..1111111.", this.policy_count)
                    this.updateData(this.policy_list[this.uplodeTag])
                    console.log(this.policy_list[this.uplodeTag], "obj")
                } else {
                    return false
                }
            },
            updateData(obj) {
                console.log(obj, "..................给什么啊", obj.insure_num, )
                new Promise((resolve, reject) => {
                    let _params = {
                        employee_list: obj,
                    }
                    add_employee(_params).then(response => {
                        console.log(response, 'synchData有什么用啊')
                        if (response.data.err == 0) {

                        } else {
                            this.errortag++
                                this.problem_list.push(response.data.info)
                        }
                        this.uplodeTag++
                            if (this.uplodeTag == this.policy_count) {
                                this.statustxt = '导入完成。成功：' + (this.policy_count - this.errortag) +
                                    '条，失败：' + this.errortag + '条'
                                this.modal_loading = false
                            } else {
                                this.sendData()
                            }
                        resolve();
                    }).catch(error => {
                        this.modal_loading = false
                        this.status = 'wrong'
                        this.statustxt = '导入失败'
                        reject(error);
                    });
                })
            },




















            exportClick() {
                this.exportModal = true
            },
            //导出员工
            exportOk() {
                var iframe = document.createElement('iframe');
                iframe.style.display = 'none';
                iframe.src = 'https://export.kuaibao365.com/kb/e1/employee/office?list='+this.exportForm.yun_org_mid.join(',')+'&status='+this.exportForm.status+'&Yid='+sessionStorage.getItem('id');
                document.body.appendChild(iframe);
                setTimeout(() => {
                    this.loading = false;
                    this.$nextTick(() => {
                        this.loading = true;
                    });
                }, 2000);
                // new Promise((resolve, reject) => {
                //     batchExportOffical(this.exportForm).then(response => {
                //         console.log(response.data)
                //         if (response.data.err == 0) {
                //             var iframe = document.createElement('iframe');
                //             iframe.style.display = 'none';
                //             iframe.src = response.data.data.url;
                //             document.body.appendChild(iframe);
                //         } else {
                //             this.$Message.error(response.data.info);
                //         }
                //         setTimeout(() => {
                //             this.loading = false;
                //             this.$nextTick(() => {
                //                 this.loading = true;
                //             });
                //         }, 2000);
                //         resolve();
                //     }).catch(error => {
                //         reject(error);
                //         setTimeout(() => {
                //             this.loading = false;
                //             this.$nextTick(() => {
                //                 this.loading = true;
                //             });
                //         }, 2000);
                //     });
                // });
            },
            orglistinit() {
                new Promise((resolve, reject) => {
                    let _params = {
                        name: ''
                    }
                    getListByName(_params).then(response => {
                        if (response.data.err == 0) {
                            this.orglist = response.data.data;

                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
                });
            },
            contractchange(value) {
                this.searchForm.join_time_start = value[0]
                this.searchForm.join_time_end = value[1]
            },
            // 点击设置显示模态框
            modalTrue() {
                this.showAddModal = true;
                // new Promise((resolve, reject) => {
                //     get_account().then(response => {
                //         console.log(response.data,".......")
                //         if (response.data.err == 0) {
                //             this.showAddModal = true;
                //             this.org=response.data.data;
                //             this.org.pwd_two = response.data.data.pwd;
                //             this.org.yun_id = this.current.yun_id
                //         } else {
                //             this.$Message.error(response.data.info);
                //         }
                //         resolve();
                //     }).catch(error => {
                //         reject(error);
                //     });
                // }); 
            },
            orgchange(value) {
                console.log(this.$refs)
                console.log(value)
                this.oname = value.label
            },
            oidremote(query) {
                if (query !== '') {
                    if (query == this.oname) {
                        this.searchForm.yun_org_mid = ''
                        return
                    }
                    this.remoteloading = true;
                    this.remoteorg(query)
                } else {
                    this.orglist = [];
                }
            },
            remoteorg: debounce(function (query) {

                new Promise((resolve, reject) => {
                    let _params = {
                        name: query
                    }
                    getListByName(_params).then(response => {
                        console.log(response.data)
                        if (response.data.err == 0) {
                            // this.emplist = response.data.data 
                            this.remoteloading = false;
                            const list = response.data.data.map(item => {
                                return {
                                    value: item.id,
                                    label: item.shortn
                                };
                            });
                            this.orglist = list.filter(item => item.label.toLowerCase().indexOf(
                                query.toLowerCase()) > -1);
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
                });
            }, 300),
            getDept() {
                new Promise((resolve, reject) => {
                    getDeptList().then(response => {
                        console.log(response)
                        if (response.data.err == 0) {
                            this.deptlist = Object.assign({}, response.data.data)
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
                })
            },
            getRank() {
                new Promise((resolve, reject) => {
                    getYunRankList().then(response => {
                        console.log(response)
                        if (response.data.err == 0) {
                            this.ranklist = Object.assign({}, response.data.data)
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
                })
            },
            toUpdate(id) {
                this.$router.push({
                    name: 'employee_update',
                    params: {
                        id: id,
                        type: 2
                    }
                });
            },
            //编辑保单
            tableEdit() {
                console.log(this.currentRow.id)
                this.toUpdate(this.currentRow.id)
            },
            //搜索保险公司change事件
            companychange(item) {
                //console.log(item)
                this.searchForm.cid = item
            },
            //远程请求保险公司
            remoteCom(query) {
                if (query !== '') {
                    this.proloading = true;
                    setTimeout(() => {
                        new Promise((resolve, reject) => {
                            let _params = {
                                name: query,
                            }
                            parteGetByName(_params).then(response => {
                                console.log(response.data)
                                if (response.data.err == 0) {
                                    this.proloading = false;
                                    const list = response.data.data.map(item => {
                                        return {
                                            value: item.id,
                                            label: item.name,
                                            pay_period: item.pay_period,
                                            period: item.period
                                        };
                                    });
                                    this.comoptions = list.filter(item => item.label.toLowerCase()
                                        .indexOf(query.toLowerCase()) > -1);
                                } else {
                                    this.$Message.error(response.data.info);
                                }
                                resolve();
                            }).catch(error => {
                                reject(error);
                            });
                        });
                    }, 200);
                } else {
                    this.comoptions = [];
                }
            },
            //时间转换
            datachange(date, obj, param) {
                obj[param] = date
            },
            headSet() {

            },
            tableCurrentChange(currentRow, oldCurrentRow) {
                console.log(currentRow)
                console.log(oldCurrentRow)
                this.tableaction = false;
                this.currentRow = currentRow
                console.log(this.currentRow)
            },
            // 搜索
            search() {
                this.tableloading = true
                this.searchForm.p = 1
                this.getList();
            },
            // 获取员工列表
            getList() {
                this.tableaction = true;
                new Promise((resolve, reject) => {
                    this.searchForm.service_type = '内勤'
                    employeeGetListOffice(this.searchForm).then(response => {
                        if (response.data.err == 0) {
                            this.tablelist = response.data.data.list;
                            console.log(this.tablelist,'..this.tablelist')
                            for(var i in this.tablelist){
                                if(this.tablelist[i].age){

                                }else{
                                    this.tablelist[i].age = '未知'
                                }
                            }
                            this.listTotal = response.data.data.total;
                            this.tableloading = false
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
                });
            },
            // 页码改变
            pageChange(page) {
                this.page = page
                this.searchForm.p = page
                this.getList()
            },
            // 每页条数改变
            pageSizeChange(pagesize) {
                this.pagesize = pagesize
                this.searchForm.pagesize = pagesize
                this.getList();
            },
            del(param) {
                new Promise((resolve, reject) => {
                    employeeDelOffice(param).then(response => {
                        if (response.data.err == 0) {
                            this.pageChange(1)
                            this.$Message.success(response.data.info);
                        } else {
                            this.$Message.error(response.data.info);
                        }
                        resolve();
                    }).catch(error => {
                        reject(error);
                    });
                });
            },
            //添加or编辑代理人，打开modal
            createBtn() {
                this.$router.push({
                    name: 'employee_create',
                    params: {
                        type: 2
                    }
                });
            },
            // 删除时弹出对话框
            tableDel() {
                this.$Modal.confirm({
                    title: '提示',
                    content: '是否要删除该员工?',
                    onOk: () => {
                        let _params = {
                            'id': this.currentRow.id,
                            'service_type': '内勤'
                        }
                        this.del(_params);
                    },
                });
            },






        }
    }
</script>